﻿@using PNProject.EF;
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout1.cshtml";
    int active = Convert.ToInt16(ViewData["page-active"]);
    int total = (int)(ViewData["page-total"]);
    int pc = (int)(ViewData["page-pc"]);
    List<int> listPage = (List<int>)(ViewData["page-list"]);
    List<Library> libs = (List<Library>)(ViewData["libs"]);
    int last = 1;
    if (listPage.Count > 1)
    {
        last = listPage.ElementAt(listPage.Count - 1);
    }
    bool lang = (bool)(ViewData["lang"]);
    string langText = lang ? "" : "en-US/";
}

<div class="search-bv">
    <form name="input" action="/@string.Concat(langText,"libraries/search")" method="get">
        <input type="text" name="query" placeholder="Từ khóa" style="width:640px; height:16px; float:left; padding:5px 10px; border:1px solid #ddd; background:white; color:#333;" />
        <input type="submit" value="Search" style="width:68px; height:28px; float:right;" />
    </form>
</div>
<div class="thuvien">
    <div class="ttthuvien">
        <p>Tiêu đề</p>
        <span>Xem / Download</span>
    </div>

    @foreach (var item in libs)
    {
        if (item.Type == 0)
        {
            <div class="boxthuvien">
                <ul class="download">
                    <li class="down-I"><a href="/@string.Concat(langText, "libraries/detail/", @item.TLink)">@item.Title</a></li>
                    <li class="down-II"><a href="/libraries/golink/@item.ElementID.ToString()" target="_blank">Download</a></li>
                </ul>
            </div>
        }
        else
        {
            <div class="boxthuvien">
                <ul class="youtube">
                    <li class="you-I"><a href="/@string.Concat(langText, "libraries/detail/", @item.TLink)">@item.Title</a></li>
                    <li class="you-II"><a href="/libraries/golink/@item.ElementID.ToString()" target="_blank">Xem link Youtube</a></li>
                </ul>
            </div>
        }
        
    }        
                        
    <div class="pageT">
        <ul>
            <li><a href="/@string.Concat(langText,"libraries/index?p=1")">Trang đầu</a></li>
            @foreach (var item in listPage)
            {
                if (item == active)
                {
                     <li class="active"><a href="/@string.Concat(langText, "libraries/index?p=", item.ToString())">@item.ToString()</a></li>
                }
                else
                {
                    <li><a href="/@string.Concat(langText, "libraries/index?p=", item.ToString())">@item.ToString()</a></li>
                }
            }
            @if (last < pc)
            {
            <li><a href="/@string.Concat(langText, "libraries/index?p=", (last + 1).ToString())">...</a></li>
            <li><a href="#"><img src="/images/icon-14.png" alt="" /></a></li>
            }
            <li><a href="/@string.Concat(langText, "libraries/index?p=", pc.ToString())">Trang cuối</a></li>
        </ul>
    </div>
    </div>
    <script type="text/javascript">
        $(document).ready(function () {
            $(".titlesub p").empty();
            var lang = document.URL.indexOf("en-US") < 0 ? true : false;
            if (lang) {
                $(".titlesub p").append("Thư viện");
                $("#ulink_home a").append("Trang chủ");
                $("#ulink_child a").append("Thư viện");
                $("#ulink_child a").attr("href", "/libraries");
            }
            else {
                $(".titlesub p").append("Libraries");
                $("#ulink_home a").append("Home");
                $("#ulink_home a").attr("href", "/en-US/home");
                $("#ulink_child a").append("Libraries");
                $("#ulink_child a").attr("href", "/en-US/libraries");
            }
        });
</script>